﻿using Microsoft.Practices.Prism.Mvvm;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Prism.Commands;
using Windows.UI.Popups;

namespace App39.ViewModels
{
    class MainPageViewModel : ViewModel, IMainPageViewModel
    {
        public override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary<string, object> viewModelState)
        {
            this.Title = navigationParameter.ToString();
        }

        string _Title = default(string);
        public string Title { get { return _Title; } set { base.SetProperty(ref _Title, value); } }

        string _Text = default(string);
        [RestorableState]
        public string Text { get { return _Text; } set { base.SetProperty(ref _Text, value); } }

        DelegateCommand<string> _JamesCommand = null;
        public DelegateCommand<string> JamesCommand
        {
            get
            {
                if (_JamesCommand != null)
                    return _JamesCommand;
                _JamesCommand = new DelegateCommand<string>
                (
                    async o =>
                    {
                        await new MessageDialog(o).ShowAsync();
                    },
                    o => { return !string.IsNullOrEmpty(this.Text); }
                );
                this.PropertyChanged += (s, e) => _JamesCommand.RaiseCanExecuteChanged();
                return _JamesCommand;
            }
        }

    }
}
